const baseSimpleList = [
  {key5811: "ABF", key511: "AF", carModel: "嘉年华"},
  {key5811: "FNN", key511: "FN", carModel: "新嘉年华1.0T"},
  {key5811: "FLN", key511: "FN", carModel: "新嘉年华1.5L"},
  {key5811: "KNF", key511: "KF", carModel: "翼搏1.0T"},
  {key5811: "KLF", key511: "KF", carModel: "翼搏1.5L"},
  {key5811: "KNF", key511: "KF", carModel: "2017款全新翼搏1.0T"},
  {key5811: "KLF", key511: "KF", carModel: "2017款全新翼博1.5L"},
  {key5811: "KCF", key511: "KF", carModel: "2017款全新翼博2.0L"},
  {key5811: "CEF", key511: "CF", carModel: "经典福克斯"},
  {key5811: "CBE", key511: "CE", carModel: "2012款新福克斯1.6L"},
  {key5811: "CCE", key511: "CE", carModel: "2012款新福克斯2.0L"},
  {key5811: "CNE", key511: "CE", carModel: "2015款全新福克斯1.0T"},
  {key5811: "CLE", key511: "CE", carModel: "2015款全新福克斯1.5T"},
  {key5811: "CBE", key511: "CE", carModel: "2015款全新福克斯1.6L"},
  {key5811: "CNR", key511: "CR", carModel: "2015款全新福克斯1.0T"},
  {key5811: "CLR", key511: "CR", carModel: "2015款全新福克斯1.5T"},
  {key5811: "CBR", key511: "CR", carModel: "2015款全新福克斯1.6L"},
  {key5811: "FLS", key511: "FS", carModel: "福睿斯"},
  {key5811: "JLE", key511: "JE", carModel: "翼虎1.5T"},
  {key5811: "JBE", key511: "JE", carModel: "翼虎1.6T"},
  {key5811: "JCE", key511: "JE", carModel: "翼虎2.0L"},
  {key5811: "JLE", key511: "JE", carModel: "新翼虎1.5T"},
  {key5811: "JCE", key511: "JE", carModel: "新翼虎2.0L"},
  {key5811: "FFF", key511: "FF", carModel: "麦柯斯"},
  {key5811: "BFF", key511: "BF", carModel: "蒙迪欧-致胜2.3L"},
  {key5811: "BCF", key511: "BF", carModel: "蒙迪欧Gtdi"},
  {key5811: "FLF", key511: "FF", carModel: "2013款新蒙迪欧1.5T"},
  {key5811: "FCF", key511: "FF", carModel: "2013款新蒙迪欧2.0L"},
  {key5811: "FLF", key511: "FF", carModel: "2017款全新蒙迪欧1.5T"},
  {key5811: "FCF", key511: "FF", carModel: "2017款全新蒙迪欧2.0L"},
  {key5811: "FCH", key511: "FH", carModel: "锐界2.0L"},
  {key5811: "FHH", key511: "FH", carModel: "锐界2.7L"},
  {key5811: "MLH", key511: "MH", carModel: "金牛座1.5T"},
  {key5811: "MCH", key511: "MH", carModel: "金牛座2.0L"},
  {key5811: "MHH", key511: "MH", carModel: "金牛座2.7L"}
];
const carModelCodeList = [
  {key5811: "ABF", key511: "AF", carModel: {value: "B299ICA", name: "嘉年华"}},
  {key5811: "FNN", key511: "FN", carModel: {value: "B299MCA 1.0T", name: "新嘉年华1.0T"}},
  {key5811: "FLN", key511: "FN", carModel: {value: "B299MCA 1.5L", name: "新嘉年华1.5L"}},
  {key5811: "KNF", key511: "KF", carModel: {value: "B515 1.0T", name: "翼搏1.0T"}},
  {key5811: "KLF", key511: "KF", carModel: {value: "B515 1.5L", name: "翼搏1.5L"}},
  {key5811: "KNF", key511: "KF", carModel: {value: "B515MCA 1.0T", name: "2017款全新翼搏1.0T"}},
  {key5811: "KLF", key511: "KF", carModel: {value: "B515MCA 1.5L", name: "2017款全新翼博1.5L"}},
  {key5811: "KCF", key511: "KF", carModel: {value: "B515MCA 2.0L", name: "2017款全新翼博2.0L"}},
  {key5811: "CEF", key511: "CF", carModel: {value: "C307", name: "经典福克斯"}},
  {key5811: "CBE", key511: "CE", carModel: {value: "C346 1.6L", name: "2012款新福克斯1.6L"}},
  {key5811: "CCE", key511: "CE", carModel: {value: "C346 2.0L", name: "2012款新福克斯2.0L"}},
  {key5811: "CNE", key511: "CE", carModel: {value: "C346MCA 1.0T", name: "2015款全新福克斯1.0T"}},
  {key5811: "CLE", key511: "CE", carModel: {value: "C346MCA 1.5T", name: "2015款全新福克斯1.5T"}},
  {key5811: "CBE", key511: "CE", carModel: {value: "C346MCA 1.6L", name: "2015款全新福克斯1.6L"}},
  {key5811: "CNR", key511: "CR", carModel: {value: "C346MCA 1.0T", name: "2015款全新福克斯1.0T"}},
  {key5811: "CLR", key511: "CR", carModel: {value: "C346MCA 1.5T", name: "2015款全新福克斯1.5T"}},
  {key5811: "CBR", key511: "CR", carModel: {value: "C346MCA 1.6L", name: "2015款全新福克斯1.6L"}},
  {key5811: "FLS", key511: "FS", carModel: {value: "C490 1.5L", name: "福睿斯"}},
  {key5811: "JLE", key511: "JE", carModel: {value: "C520 1.5T", name: "翼虎1.5T"}},
  {key5811: "JBE", key511: "JE", carModel: {value: "C520 1.6T", name: "翼虎1.6T"}},
  {key5811: "JCE", key511: "JE", carModel: {value: "C520 2.0L", name: "翼虎2.0L"}},
  {key5811: "JLE", key511: "JE", carModel: {value: "C520MCA 1.5T", name: "新翼虎1.5T"}},
  {key5811: "JCE", key511: "JE", carModel: {value: "C520MCA 2.0L", name: "新翼虎2.0L"}},
  {key5811: "FFF", key511: "FF", carModel: {value: "CD340 2.3L", name: "麦柯斯"}},
  {key5811: "FLF", key511: "FF", carModel: {value: "CD391 1.5T", name: "2013款新蒙迪欧1.5T"}},
  {key5811: "FCF", key511: "FF", carModel: {value: "CD391 2.0L", name: "2013款新蒙迪欧2.0L"}},
  {key5811: "FLF", key511: "FF", carModel: {value: "CD391MCA 1.5T", name: "2017款全新蒙迪欧1.5T"}},
  {key5811: "FCF", key511: "FF", carModel: {value: "CD391MCA 2.0L", name: "2017款全新蒙迪欧2.0L"}},
  {key5811: "BFF", key511: "BF", carModel: {value: "CD345 2.3L", name: "蒙迪欧-致胜2.3L"}},
  {key5811: "BCF", key511: "BF", carModel: {value: "CD345-ZS 2.0L", name: "蒙迪欧Gtdi"}},
  {key5811: "FCH", key511: "FH", carModel: {value: "CD539 2.0L", name: "锐界2.0L"}},
  {key5811: "FHH", key511: "FH", carModel: {value: "CD539 2.7L", name: "锐界2.7L"}},
  {key5811: "MLH", key511: "MH", carModel: {value: "D568 1.5T", name: "金牛座1.5T"}},
  {key5811: "MCH", key511: "MH", carModel: {value: "D568 2.0L", name: "金牛座2.0L"}},
  {key5811: "MHH", key511: "MH", carModel: {value: "D568 2.7L", name: "金牛座2.7L"}}
];

function getCM (vin) {
  if (!vin) {
    return baseSimpleList;
  }
  let carModelList = get5811(vin);

  if (!carModelList || carModelList.length < 1) {
    carModelList = get511(vin);
  }

  return carModelList;
}

function get5811 (vin) {
  let vin5 = vin.substring(4, 5);
  let vin8 = vin.substring(7, 8);
  let vin11 = vin.substring(10, 11);
  let key5811 = vin5 + vin8 + vin11;
  let carModelList = [];
  baseSimpleList.forEach((baseCarModel) => {
    if (baseCarModel.key5811 === key5811) {
      carModelList.push(baseCarModel.carModel);
    }
  });
  return carModelList;
}

function get511 (vin) {
  let vin5 = vin.substring(4, 5);
  let vin11 = vin.substring(10, 11);
  let key511 = vin5 + vin11;
  let carModelList = [];
  baseSimpleList.forEach((baseCarModel) => {
    if (baseCarModel.key511 === key511) {
      carModelList.push(baseCarModel.carModel);
    }
  });
  return carModelList;
}

function getTopCm (vin) {
  let carModel = null;
  let cmList = getCM(vin);
  if (cmList && cmList.length > 0) {
    carModel = cmList[0];
    return carModel;
  }
  return null;
}

function getCMCode (vin) {
  if (!vin) {
    return [];
  }
  let carModelList = get5811Code(vin);

  if (!carModelList || carModelList.length < 1) {
    carModelList = get511Code(vin);
  }

  return carModelList;
}

function get5811Code (vin) {
  vin = vin + "";
  let vin5 = vin.substring(4, 5);
  let vin8 = vin.substring(7, 8);
  let vin11 = vin.substring(10, 11);
  let key5811 = vin5 + vin8 + vin11;
  let carModelList = [];
  carModelCodeList.forEach((baseCarModel) => {
    if (baseCarModel.key5811 === key5811) {
      carModelList.push(baseCarModel.carModel);
    }
  });
  return carModelList;
}

function get511Code (vin) {
  let vin5 = vin.substring(4, 5);
  let vin11 = vin.substring(10, 11);
  let key511 = vin5 + vin11;
  let carModelList = [];
  carModelCodeList.forEach((baseCarModel) => {
    if (baseCarModel.key511 === key511) {
      carModelList.push(baseCarModel.carModel);
    }
  });
  return carModelList;
}

export default {
  getCM: function (vin) {
    return getCM(vin);
  },
  getTopCm: function (vin) {
    return getTopCm(vin);
  },
  getCMCode: function (vin) {
    return getCMCode(vin);
  }
}
